﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Easy.BLL;
using Easy.Operation.Data;

namespace Easy.Web.Pages.PrivilegePages
{
    public partial class BusinessUnitListPage : BasePage
    {
        public String ViewName;
        public String EntinyName;
        protected void Page_Load(object sender, EventArgs e)
        {
            bool DoNotShowButton;
            try
            {
                EntinyName = "systemuser";//Request["entityname"].ToLower();
            }
            catch (Exception)
            {
                Response.StatusCode = 404;
                return;
            }
            try
            {
                ViewName = Request["viewname"].ToLower();
            }
            catch (Exception)
            {
                ViewName = "DefaultView";
            }

            try
            {
                if (int.Parse(Request["DoNotShowButton"]) > 0)
                {
                    DoNotShowButton = true;
                }
                else
                {
                    DoNotShowButton = false;
                }
            }
            catch (Exception)
            {
                DoNotShowButton = false;
            }

            PageView view = new PageView(EntinyName, this.GetSystemUser(), ViewName);

            this.CoreScript.Text = string.Format(@"<script>
                                                     var EntityName='{0}';

                                                    var EntityViews={1};
                                                    var ViewName = '{2}';
                                                    var Privilege={3};
                                                    var DoNotShowButton={4};
                                                    </script>
                                                    ", 
                                                    view.EntityName,
                                                    //JsonConvert.SerializeObject(view.Fields),
                                                    //JsonConvert.SerializeObject(view.Options),
                                                    JsonConvert.SerializeObject(view.ViewsPC), 
                                                    view.ViewName,
                                                    JsonConvert.SerializeObject(view.UserPrivilege),
                                                    DoNotShowButton ? "1" : "0");
        }
    }
}